package com.wnhz.work.jy.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.wnhz.work.jy.R;
import com.wnhz.work.jy.bean.CollectBean;

import org.xutils.x;

import java.util.List;

/**
 * Created by Administrator on 2016/10/9 0009.
 */
public class CollectAdapter extends BaseAdapter {
    private Context context;
    private List<CollectBean> collectList;
    private View.OnClickListener listener;

    public CollectAdapter(Context context, List<CollectBean> collectList, View.OnClickListener listener) {
        this.context = context;
        this.collectList = collectList;
        this.listener = listener;
    }

    @Override
    public int getCount() {
        return collectList.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        CollectViewHolde viewHolde = new CollectViewHolde();
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.collect_item, null);
            viewHolde.iv_pic = (ImageView) convertView.findViewById(R.id.iv_pic);
            viewHolde.tv_title = (TextView) convertView.findViewById(R.id.tv_title);
            viewHolde.tv_type = (TextView) convertView.findViewById(R.id.tv_type);
            viewHolde.tv_price = (TextView) convertView.findViewById(R.id.tv_price);
            viewHolde.tv_cancel = (TextView) convertView.findViewById(R.id.tv_cancel);//取消收藏

            convertView.setTag(viewHolde);
        } else {
            viewHolde = (CollectViewHolde) convertView.getTag();
        }

        x.image().bind(viewHolde.iv_pic,collectList.get(position).getGoodImg());
//        ImageLoader.getInstance().displayImage(collectList.get(position).getImage(),viewHolde.iv_pic);
        viewHolde.tv_title.setText(collectList.get(position).getGoodName());
//        viewHolde.tv_type.setText(collectList.get(position).getType());
        viewHolde.tv_price.setText("¥"+collectList.get(position).getGoodPrice());

        viewHolde.tv_cancel.setTag(position);
        viewHolde.tv_cancel.setOnClickListener(listener);

        return convertView;
    }

    class CollectViewHolde {
        ImageView iv_pic;
        TextView tv_title;
        TextView tv_type;
        TextView tv_price;
        TextView tv_cancel;
    }
}
